<?php
namespace app\common\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Log;
use app\common\request\Curl;
use app\common\request\ClientLai;
use app\common\model\CarsInfo;
use app\common\model\CarsTemp;

class Fill extends Command
{
	protected function configure()
    {
        $this->setName('fill')->setDescription('车辆数据');
    }

    protected function execute(Input $input, Output $output)
    {
        $this->acquire();
    	$output->writeln('success');
    }

    public function acquire(){
    	
    	$param = Db::name('cars_info')->where('network_status','null')->field('car_unique_id')->select();
    	$data['car_unique_id_arr'] = array_column($param,'car_unique_id');
	    $curl = new Curl;
        $header = config('car_hear.header');
        $url = config('car_hear.url');
        $res = $curl->set('CURLOPT_HTTPHEADER',$header)->post($data)->url($url);
        if ($curl->error()) {
            Log::record($curl->message(),'error');
        }else{
                // 任务进程信息
            $info = $curl->info();               
            if($info['http_code'] == 500){ 
                Log::record('对方服务器错误','error');  
                exit();
            }else{
                // 任务结果内容
                $content = $curl->data();
            }
        }
        $arr = json_decode($content,true);
        if($arr['result'] == 0){  
            try {
                $model = new CarsInfo;
                $model->allowField(true)->saveAll($arr['data']);
                
            } catch (\Exception $e) {
                Log::record('[更新cars_info表车辆数据]'.$e->getMessage(),'error');
                return false;
            } 

        }    
    }
    
    
}	